package ink.xiaobaibai.config;

import ink.xiaobaibai.filter.TokenAuthenticationFilter;
import ink.xiaobaibai.provider.TokenAuthenticationProvider;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.authentication.logout.LogoutFilter;

/**
 * @description: jwt登录集装类
 * @author: 小白白
 * @create: 2021-05-15
 **/

public class TokenAuthenticationConfig<T extends TokenAuthenticationConfig<T, B>, B extends HttpSecurityBuilder<B>>
        extends AbstractHttpConfigurer<T, B> {

    @Override
    public void configure(B http) throws Exception {
        TokenAuthenticationFilter filter =
                new TokenAuthenticationFilter(http.getSharedObject(AuthenticationManager.class));
        filter = this.postProcess(filter);
        http.authenticationProvider(new TokenAuthenticationProvider())
                .addFilterAfter(filter, LogoutFilter.class);
    }
}
